<?php
class articles extends parent_class
{
	public $articles=array();
	public $teacher=0;
	
	public function __construct($teacher=0)
	{
		if ($teacher==0)
		{
			return $this->get_simple();
		}
		else
		{
			if ($teacher>0)
			{
				return $this->get_byteacher($teacher);
			}
			else
			{
				return false;
			}
		}
	}
	
	public function get_byteacher($id=0)
	{
		if ($id==0)
		{
			if ($this->teacher>0)
			{
				$id=$this->teacher;
			}
			else
			{
				return false;
			}
		}
		$this->reset();
		$query="SELECT `id` FROM `articles` WHERE `author`='".intval($id)."'";
		if ($result=db::$db->query($query))
		{
			if ($result->num_rows>0)
			{
				while ($row=$result->fetch_object())
				{
					$this->articles[]=new article($row->id);
				}
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			$this->error(2);
		}
	}
	
	public function get_simple()
	{
		$this->reset();
		$query="SELECT `id` FROM `articles` WHERE 1";
		if ($result=db::$db->query($query))
		{
			if ($result->num_rows>0)
			{
				while ($row=$result->fetch_object())
				{
					$this->articles[]=new article($row->id);
				}
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			$this->error(2);
		}
		
	}
	
	public function reset()
	{
		$this->articles=array();
	}
	
	public function returnit($str="")
	{
		if (trim($str)=="")
		{
			return false;
		}
		
		if ($this->articles)
		{
			$str2="";
			foreach($this->articles as $article)
			{
				$str2.=$article->returnit($str);
			}
			return $str2;
		}
		else
		{
			return false;
		}
	}
}
?>